package com.study.genericity;

/**
 * 泛型
 */
public class GenericityMain {
    public static void main(String[] args) throws IllegalAccessException, InstantiationException {
       // genericClassTest();
        //converterTest();
       /* Generic<Integer> gInteger = new Generic<Integer>(123);
        Generic<Number> gNumber = new Generic<Number>(456);*/
        //showKeyValue1(gInteger);
        //showKeyValue1(gNumber);

       /* showKeyValue2(gInteger);
        showKeyValue2(gNumber);*/
        Generic generic = new Generic("22");
        Object o = generic.genericMethod(String.class);
    }
    public static void showKeyValue1(Generic<Number> obj){
        System.out.println(obj.getKey());
    }
    public static void showKeyValue2(Generic<?> obj){
        System.out.println(obj.getKey());
    }
    private static void converterTest() {
        ClassAConverter classAConverter = new ClassAConverter();
        ClassA classA = new ClassA("a");
        ClassB classB = classAConverter.convertTo(classA);
    }

    private static void genericClassTest() {
        //泛型的类型参数只能是类类型（包括自定义类），不能是简单类型
//传入的实参类型需与泛型的类型参数类型相同，即为Integer.
        Generic<Integer> genericInteger = new Generic<Integer>(123456);

//传入的实参类型需与泛型的类型参数类型相同，即为String.
        Generic<String> genericString = new Generic<String>("key_vlaue");
        System.out.println(genericInteger.getKey());
        System.out.println(genericString.getKey());
    }
}
